package com.study.security.domain;

import com.study.modules.saas.repository.enums.UserType;
import com.study.modules.saas.repository.model.UserDO;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class CurrentUser implements UserDetails {

    private String getUserUuidByName;

    private String uuid;
    private String username;
    private String token;
    private Integer roleId;

    private List<String> permissions;

    private boolean admin;

    public CurrentUser() {

    }

    public CurrentUser(UserDO userDO, String token) {
        this.uuid = userDO.getUuid();
        this.username = userDO.getUserName();
        this.token = token;
        this.roleId = userDO.getRoleDO().getId();

        if(UserType.ADMIN.equals(userDO.getType())){
            this.admin = true;
        }
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    /**
     * 返回密码，认证后会校验密码
     *
     * @return
     */
    @Override
    public String getPassword() {
        return this.uuid;
    }

    @Override
    public String getUsername() {
        return this.uuid;
    }

    /**
     * 指示用户的帐户是否已过期。无法验证过期帐户。
     *
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 指示用户是锁定还是解锁。无法对锁定的用户进行身份验证。
     *
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 指示用户的凭据（密码）是否已过期。期满凭据阻止身份验证。
     *
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 指示用户是启用还是禁用。无法删除禁用的用户已验证。
     *
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
